// 封装异步组件
import { useIntersectionObserver } from '@vueuse/core'

export const useLazyData = () => {
  const targetIsVisibel = ref([])
  const target = ref[null]
  const { stop } = useIntersectionObserver(target, ([{ isIntersecting }]) => {
    if(isIntersecting) {
		targetIsVisibel.value = isIntersecting;
      // isIntersecting 为 true,证明 target 进入可视区, 此时发起请求
      // apiFn().then(ret => targetIsVisibel.value = ret.data)
      // 取消监听组件进入视图区域这一行为
        // stop()
     }
   })

  return { targetIsVisibel, target }
}